﻿
 function getTargetElement(evt) {
   var elem;
   if (evt.target)
   {
     elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
   }
   else
   {
     elem = evt.srcElement;
   }
   return elem;
 }
 function OnClientTreeNodeChecked(evt)
 {
   evt = (evt) ? evt : ((window.event) ? window.event : "");
   if(evt == "")
   {
     return
   }
   var obj = getTargetElement(evt);
   var hasTreeNode = false;
   var treeNodeChecked;
   if (obj.tagName == "INPUT" && obj.type == "checkbox") {
       var treeNode = obj;
     treeNodeChecked = treeNode.checked;
     while (obj.tagName != "TABLE")
     {
       obj = obj.parentNode;
     }
     var parentTreeLevel = obj.rows[0].cells.length;
     var parentTreeNode = obj.rows[0].cells[0];
     var containerDiv = obj.parentNode;
     if(containerDiv == null)
     {
         return;
     }
     var tables = containerDiv.getElementsByTagName("TABLE");
     var tableCount = tables.length;
     if(tableCount < 1)
     {
         return;
     }  
     for (i = 0; i < tableCount; i++)
     {
       if (tables[i] == obj)
       {
         hasTreeNode = true;
         i++;
         if (i == tableCount)
         {
           return;
         }
       }
       if (hasTreeNode)
       {
         var childTreeLevel = tables[i].rows[0].cells.length;
         if (childTreeLevel > parentTreeLevel)
         {
           var cell = tables[i].rows[0].cells[childTreeLevel - 1];
           var inputs = cell.getElementsByTagName("INPUT");
           if (inputs != null && inputs.length > 0) {
               inputs[0].checked = treeNodeChecked;
           }
         }
         else
         {
           return;
         }
       }
     }    
   }
 }
